
import React from 'react';
import styles from './index.module.less';
import { Spin } from '@/components/base';

const Loading = () => <Spin wrapperClassName={styles.loading} tip="模块加载中..." ><div /></Spin>;

export const lazy = (factory: () => Promise<any>, load = <Loading />) => (props: any) => {
    const [Ct, setCt] = React.useState<any>();
    React.useEffect(() => {
        (async () => {
            const myCt = await factory();
            setCt(myCt);
        })();
    }, []);

    return (Ct && Ct.default) ? <Ct.default {...props} /> : load;
};

